home *** CD-ROM | disk | FTP | other *** search
/ JCSM Shareware Collection 1996 September / JCSM Shareware Collection (JCS Distribution) (September 1996).ISO / bother__ / cenvid.zip / CENVIDOS.ZIP / AUTOLOAD.CMM < prev    next >
Text File  |  1995-02-14  |  5KB  |  168 lines

  1. // AutoLoad.cmm
  2.  
  3. //**************************************************************************
  4. //****** BEGIN SECTION TO HANDLE INTERNAL COMMANDS FOR THE CLI SHELL *******
  5. //**************************************************************************
  6.  
  7. // create and sort list of commands for CMD.EXE call
  8. SystemCommands = {
  9.    "DIR",
  10.    "CLS",
  11.    "MKDIR",
  12.    "MD",
  13.    "RMDIR",
  14.    "RD",
  15.    "ERASE",
  16.    "DEL",
  17.    "TYPE",
  18. };
  19. qsort(SystemCommands,"stricmp");
  20.  
  21. // create and sort list of commands handled internally
  22. InternalCommands = {
  23.    "CD",
  24.    "SET"
  25. };
  26. qsort(InternalCommands,"stricmp");
  27.  
  28. // set up filter to handle each command input
  29. ShellFilterCommand("AutoloadFilterCommand");
  30.  
  31. AutoloadFilterCommand(pCommand)
  32. {
  33.    // if command found in SystemCommands list then execute it immediately
  34.    // with CMD.EXE then, else check internal cmds and some others
  35.    if ( 1 == sscanf(pCommand,"%s",lCommand) ) {
  36.       if ( -1 != bsearch(lCommand,SystemCommands,"stricmp") ) {
  37.          system(pCommand);
  38.          pCommand[0] = '\0';
  39.       } else if ( -1 != bsearch(lCommand,InternalCommands,"stricmp") ) {
  40.          sprintf(lInternalFunction,"InternalCommand_%s",strupr(lCommand));
  41.          lParm = pCommand + strlen(lCommand);
  42.          while( isspace(lParm[0]) ) lParm++;
  43.          function(lInternalFunction,lParm);
  44.          pCommand[0] = '\0';
  45.       } else if ( !strcmp(lCommand+1,":") ) {
  46.          // change drive
  47.          #define ORD_DOS32SETDEFAULTDISK  220
  48.          DynamicLink("doscalls",ORD_DOS32SETDEFAULTDISK,BIT32,CDECL,
  49.                      toupper(lCommand[0])-'A'+1);
  50.          pCommand[0] = '\0';
  51.       }
  52.    }
  53. }
  54.  
  55. InternalCommand_CD(pParm)
  56. {
  57.    // change directory
  58.    if ( !pParm[0] ) {
  59.       // no other argument, so just display current dir
  60.       printf("%s\n",FullPath("."));
  61.    } else {
  62.       lReg.ah = 0x3B;
  63.       lReg.ds = segment(pParm);
  64.       lReg.dx = offset(pParm);
  65.       interrupt(0x21,lReg);
  66.    }
  67. }
  68.  
  69. //************************************************************************
  70. //****** END SECTION TO HANDLE INTERNAL COMMANDS FOR THE CLI SHELL *******
  71. //************************************************************************
  72.  
  73.  
  74.  
  75. //****************************************************************************
  76. //****** BEGIN SECTION TO HANDLE HISTORY AND EDITING FOR THE CLI SHELL *******
  77. //****************************************************************************
  78.  
  79. #define EXT_KEY_HOME    0x47
  80. #define EXT_KEY_END     0x4F
  81. #define EXT_KEY_UP      0x48
  82. #define EXT_KEY_DOWN    0x50
  83.  
  84. #define HISTORY_MAX_MEMORY     20   // maximum values to hold in history
  85. gHistoryList;
  86. gHistoryCount = 0;
  87. gReviewLine = HISTORY_MAX_MEMORY;   // when scrolling through buffer, this is line being reviewed
  88.  
  89. // set up filter to handle every special character input
  90. ShellFilterCharacter("AutoloadFilterCharacter",False);
  91.  
  92. AutoloadFilterCharacter(pCommand,pPosition,pKey,pIsExtended,pIsAlnum)
  93. {
  94.    if ( pIsExtended ) {
  95.       switch( pKey ) {
  96.          case EXT_KEY_HOME:
  97.             pPosition = 0;
  98.             break;
  99.          case EXT_KEY_END:  // END
  100.             pPosition = strlen(pCommand);
  101.             break;
  102.          case EXT_KEY_UP:
  103.             if ( gHistoryCount ) {
  104.                if ( gHistoryCount <= ++gReviewLine )
  105.                   gReviewLine = 0;
  106.                strcpy(pCommand,gHistoryList[gReviewLine]);
  107.                pPosition = strlen(pCommand);
  108.                pKey = 0;
  109.                return True;
  110.             }
  111.             break;
  112.          case EXT_KEY_DOWN:
  113.             if ( gHistoryCount ) {
  114.                if ( --gReviewLine < 0 )
  115.                   gReviewLine = gHistoryCount - 1;
  116.                strcpy(pCommand,gHistoryList[gReviewLine]);
  117.                pPosition = strlen(pCommand);
  118.                pKey = 0;
  119.                return True;
  120.             }
  121.             break;
  122.       }
  123.    } else if ( '\r' == pKey ) {
  124.       AddToHistory(pCommand);
  125.    }
  126.    return False;
  127. }
  128.  
  129. AddToHistory(pCommand)
  130. {
  131.    // skip all spaces at beginning of command
  132.    strcpy(lCommand,pCommand);
  133.    lCommand += strspn(lCommand," ");
  134.    // remove any spaces at end of command
  135.    while ( (lLastSpace = strrchr(lCommand,' '))  &&  !lLastSpace[1] )
  136.       lLastSpace[0] = '\0';
  137.  
  138.    // if no command remains then do not save
  139.    if ( !lCommand[0] )
  140.       return;
  141.  
  142.    // if this entry is already in the history then remove that entry so this
  143.    // one can replace as most recent.  Otherwise remove oldest entry if there
  144.    // are up to max in the buffer
  145.    bool lNewEntry = True;
  146.    for ( lOldEntry = 0; lOldEntry < gHistoryCount; lOldEntry++ ) {
  147.       if ( !stricmp(lCommand,gHistoryList[lOldEntry]) ) {
  148.          lNewEntry = False;
  149.          break;
  150.       }
  151.    }
  152.  
  153.    // move all entries down one to fill in the old gap
  154.    while ( lOldEntry-- )
  155.       gHistoryList[lOldEntry+1] = gHistoryList[lOldEntry];
  156.  
  157.    // new command goes to top of list
  158.    gHistoryList[0] = lCommand;
  159.    if ( gHistoryCount < HISTORY_MAX_MEMORY  &&  lNewEntry )
  160.       gHistoryCount++;
  161.    gReviewLine = gHistoryCount;
  162. }
  163.  
  164. //**************************************************************************
  165. //****** END SECTION TO HANDLE HISTORY AND EDITING FOR THE CLI SHELL *******
  166. //**************************************************************************
  167.  
  168.